package com.ruoyi.verify.utils;

import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;

import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.verify.mapper.VerifyTemplateMapper;


public class MyUtils  extends BaseController{
	@Autowired
	VerifyTemplateMapper verifyTemplateMapper;
	protected Map<String,Object> jacResultMsobj(String result)
	{   
		Map<String,Object> r = new HashMap<String,Object>();
		if ("1".equals(result))
		{
		r.put("msg", "success");
		r.put("code", "0");
		return r;
		}
			if (StringUtils.contains(result, "管理员"))
			{
				r.put("msg", result);
				r.put("code", "500");
				return r;
			}
			else
		{
			r.put("msg", result);
			r.put("code", "505");
			return r;
		}
	}
	
	protected Map<String,String> jacResultMsg(String result)
	{   
		Map<String,String> r = new HashMap<String,String>();
		if ("1".equals(result))
		{
		r.put("msg", "success");
		r.put("code", "0");
		return r;
		}
			if (StringUtils.contains(result, "管理员"))
			{
				r.put("msg", result);
				r.put("code", "500");
				return r;
			}
			else
		{
			r.put("msg", result);
			r.put("code", "505");
			return r;
		}
	}
	

    /**
     * 响应返回结果
     * 
     * @param rows 影响行数(List)
     * @return 操作结果
     */
    protected R jacResult(List<?> list)
    {
        Map<String, Object> m = new HashMap<String, Object>();
        m.put("rows", list);
        return R.ok(m);
    }
    
    
    /**
     * 响应返回结果
     * 
     * @param rows 影响行数(List)
     * @return 操作结果
     */
    protected R jacResultLinkedMap(LinkedHashMap<String, Object> linkedmap)
    {
        Map<String, Object> m = new HashMap<String, Object>();
        m.put("rows", linkedmap);
        return R.ok(m);
    }
    
    /**
     * 响应返回结果
     * 
     * @param rows 影响行数(String)
     * @return 操作结果
     */
    protected R jacResultString(String key,String value)
    {
        Map<String, Object> m = new HashMap<String, Object>();
        Map<String, String> n = new HashMap<String, String>();
        List<Map<String, String>> list = new ArrayList<Map<String, String>>();
        n.put(key, value);
        list.add(n);
        m.put("rows", list);
        return R.ok(m);
    }
	
	protected String getUserId()
	{
	 return ServletUtils.getRequest().getHeader(Constants.CURRENT_USERNAME);
	}
	
	protected String getUserName()
	{   
	 return verifyTemplateMapper.selectUserNameById(ServletUtils.getRequest().getHeader(Constants.CURRENT_ID));
	}
	
	
	protected String getTime()
	{
	 return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
	}
	
	
}
